<template>
	<view class="goods">
		<view class="goods-list-title">
			<view class="goods-list-left">
				<radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="getAddRadio"></radio>
				<image :src="goods.goods_small_logo" mode="" @click="goodsEmit"></image>
			</view>
			<view class="goods-list-right">
				<view>{{goods.goods_name}}</view>
				<view class="goods-money">
					<view class="goods-moneys">￥{{goods.goods_price | toFixed }}</view>
					<uni-number-box :min="1"  @change="numChangeValue" :value="goods.goods_count" v-if="showNum"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from "vuex"
	export default {
		name: "goods-item",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {

			};
		},

		filters: {
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			...mapMutations('cart_m', ['updateGoodsState']),
			goodsEmit() {
				this.$emit('click')
			},
			getAddRadio() {
				console.log(111)
				const goods_id_state = {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state,
				}
				this.$emit('radioChange', goods_id_state);
				// this.updateGoodsState(goods_id_state);
			},
			numChangeValue(value){
				console.log(value);
				this.$emit('click',{
					goods_id:this.goods.goods_id,
					goods_count:value
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods {
		.goods-list-title {
			display: flex;
			width: 100%;
			height: 200rpx;
			margin: 20rpx;

			.goods-list-left {
				width: 300rpx;
				height: 100%;
				display: flex;
				align-items: center;

				image {
					width: 200rpx;
					height: 200rpx;
				}
			}

			.goods-list-right {
				font-size: 28rpx;
				margin: 10rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.goods-money {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.goods-moneys{
						color:#c00000;
					}
				}
			}
		}
	}
</style>
